/*
 * Canvas Game Engine - Gradient Module
 *
 * version: 0.1
 *
 * author: Fabio Rotondo <fabio@rotondo.it>
 *
 */

// Creates a new CGE Gradient
// Parameters:
//
// 	- ih: 	CGEGradientHandler instance
// 	- type:  Gradient type ( h - horizontal / v - vertical (default) / d - diagonal )
// 	- name: gradient name
function CGEGradient ( gh, type, name, size )
{
	var self = this;

	this.gh  = gh;

	switch ( type )
	{
		case "h":
			this.gradient = CGE.canvas.ctxt.createLinearGradient ( 0, 0, size, 0 );
			break;

		case "d":
			this.gradient = CGE.canvas.ctxt.createLinearGradient ( 0, 0, size, size );
			break;
		default: 
			this.gradient = CGE.canvas.ctxt.createLinearGradient ( 0, 0, 0, size );
	}

	this.alpha = 100;
}

CGEGradient.prototype.add = function ( pos, color )
{
	this.gradient.addColorStop ( pos, color );
};

CGEGradient.prototype.blit = function ( x, y, w, h )
{
	CGE.canvas.ctxt.fillStyle = this.gradient;
	CGE.canvas.ctxt.fillRect ( x, y, w, h );
};


function CGEGradientHandler ()
{
	this.gradients = {};
}

CGEGradientHandler.prototype.add = function ( type, name, size )
{
	i = new CGEGradient ( this, type, name, size );
	this.gradients [ name ] = i;

	return i;
};

CGEGradientHandler.prototype.get = function ( name )
{
	return this.gradients [ name ];
};

CGEGradientHandler.prototype.ready = function () { return true; };

// Register the GradientHandler to the system
CGE.register ( "gradient_handler", new CGEGradientHandler () );
